<?=view('admin.common.header')?>
<?=view('admin.common.nav')?>
<div class="container">
    <div class="row">
        <div class="panel panel-default">
            <div class="panel-heading">
                任务列表<a href="<?= url("admin/jobs/add") ?>" class="btn btn-success btn-xs eveAdd" style="float: right;">发布新任务</a>
            </div>
            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>工单编号</th>
                        <th>小区</th>
                        <th>客户名</th>
                        <th>联系电话</th>
                        <th>任务类型</th>
                        <th>装机地址</th>
                        <th>创建时间</th>
                        <th>工单状态</th>
                        <th>#</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($jobs && count($jobs)): ?>
                    <?php foreach ($jobs as $val): ?>
                    <tr>
                        <td><?=$val->jnum?></td>
                        <td><?=$val->strPlot()?></td>
                        <td><?=$val->cname?></td>
                        <td><?=$val->cphone?></td>
                        <td><?=$val->btype?></td>
                        <td><?=$val->address?></td>
                        <td><?=$val->strCtime()?></td>
                        <td><?=$val->strJobStatus()?></td>
                        <td>
                            <?php if ($val->status == 0): ?>
                            <a href="#" class="btn btn-xs btn-success">派发任务</a>
                            <?php endif;?>
                            <?php if (in_array($val->status, array(1, 2, 3))): ?>
                            <a href="#" class="btn btn-xs btn-info eveRec" data-info='<?=$val->strReciver()?>'>查看接单人</a>
                            <?php endif; ?>
                            <?php if ($val->status == 2): ?>
                            <a href="#" class="btn btn-xs btn-info eveTick" data-info='<?=$val->strTick()?>'>反馈信息</a>
                            <a href="<?=url("admin/jobs/changereciver/{$val->id}/{$val->plotid}")?>" onclick="return false;" class="btn btn-xs btn-success eveChange">转派任务</a>
                            <?php endif; ?>
                            <?php if ($val->status == 3): ?>
                            <a href="#" class="btn btn-xs btn-info eveTick" data-info='<?=$val->strTick()?>'>回单信息</a>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
            <?= $jobs->render() ?>
        </div> 
    </div>
</div>
<script>
    $('.eveRec').click(function(){
        var i=0, info = eval('('+$(this).attr('data-info')+')'), cont='<div style="padding: 30px;">';
        for (; i < info.length; i++) {
            cont += "<p>姓名： "+info[i].name+"</p><p>联系电话："+info[i].phone+"</p><p>接单时间："+info[i].ctime+"</p><p>是否转发(0：未转发，1：已转发)： <kbd>"+info[i].status+"</kbd></p><hr>"
        }
        cont += "</div>";
        layer.open({
            type: 1,
            title: false,
            closeBtn: false,
            shadeClose: true,
            content: cont
        });
        return false;
    });
    $('.eveTick').click(function(){
        var i=0, info = eval('('+$(this).attr('data-info')+')'), cont='<div style="padding: 30px;">';
        for (; i < info.length; i++) {
            cont += "<p>反馈人： "+info[i].name+"</p><p>联系电话："+info[i].phone+
                    "</p><p>接单时间："+info[i].recvtime+"</p><p>反馈/回单时间："+info[i].btime+"</p><p>类型(1：反馈 2：回单)： <kbd>"+info[i].type+
                    "</kbd></p>";
            if (info[i].type==1) {
                cont += "<p>反馈原因："+info[i].causename+"</p><p>处理建议："+info[i].suggest+"</p>";
            }
            cont +="<hr>";
        }
        cont += "</div>";
        layer.open({
            type: 1,
            title: false,
            closeBtn: false,
            shadeClose: true,
            content: cont
        });
        return false;
    });
    $(".eveChange").click(function(){
        var url = $(this).attr("href");
        layer.open({
            type: 2,
            title: '转派任务',
            shadeClose: false,
            shade: 0.8,
            area: ['500px', '460px'],
            content: url
        }); 
        return false;
    });
</script>
<?=view('admin.common.footer')?>